﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ThreadInDifferentContext
{
    class Program
    {
        [Synchronization]
        public class ContextBound : ContextBoundObject
        {
            public void Test()
            {
                ShowMessage();
            }
        }

        static void Main(string[] args)
        {
            //当前应用程序域信息
            Console.WriteLine("CurrentAppDomain start!");
            ShowMessage();

            //在上下文绑定对象中运行线程
            ContextBound contextBound = new ContextBound();
            contextBound.Test();
            Console.ReadKey();
        }

        public static void ShowMessage()
        {
            var message = string.Format(" CurrentThreadID is:{0}\tContextID is:{1}",
                Thread.CurrentThread.ManagedThreadId, Thread.CurrentContext.ContextID);
            Console.WriteLine(message);
        }
    }
}
